// 拦截器

import { Action, Interceptor, InterceptorInterface } from "routing-controllers";
import { Service } from "typedi";

@Service()
@Interceptor()
export class AutoAssignJSONInterceptor implements InterceptorInterface {

    intercept(action: Action, content: any) {
        if (typeof content == 'object') {
            return JSON.stringify(Object.assign({message: 'ok'}, content), (_, v)=>typeof v === 'bigint' ? v.toString(): v);
        }
        return JSON.stringify({message: content}, (_, v)=>typeof v === 'bigint' ? v.toString(): v);
    }
}